package logic

import (
	"context"
	"doctor-medicine-system/models/mysql"
	"errors"

	"doctor-medicine-system/doctorrpc/doctorrpc"
	"doctor-medicine-system/doctorrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type MedicineListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewMedicineListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MedicineListLogic {
	return &MedicineListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *MedicineListLogic) MedicineList(in *doctorrpc.MedicineListRequest) (*doctorrpc.MedicineListResponse, error) {
	// todo: add your logic here and delete this line

	var doctor mysql.Doctor

	if err := doctor.FindDoctorById(mysql.DB, in.DoctorId); err != nil {
		return nil, errors.New("医生不存在")
	}

	var list []*doctorrpc.MedicineList

	list = mysql.MedicineList(mysql.DB, in.DoctorId, list)

	return &doctorrpc.MedicineListResponse{
		List: list,
	}, nil
}
